ARC074 D - 3N Numbers
提出
code: python
n = int(input())
a = list(map(int, input().split()))
for i in range(1, len(a)):
a_sum.append(a_sum-1 + ai) print(a_sum)
解答
code: python
import heapq
n = int(input())
a = list(map(int, input().split()))
former, latter = a:n, [-1 * i for i in a2*n:] # print(former, latter)
sum_former, sum_latter = sum(former), sum(latter)
heapq.heapify(former)
heapq.heapify(latter)
for i in range(n, 2*n):
p = heapq.heappushpop(former, v)
sum_former += v - p
resultsi-n+1 += sum_former for i in range(2*n-1, n-1, -1):
p = heapq.heappushpop(latter, v)
sum_latter += v - p
print(max(results))
code: python
import heapq
n = int(input())
a = list(map(int, input().split()))
# print(a)
# 左から left 個のところで分割して
# (左 left 個のうち大きい順に n 個の和) - (右 n-left 個のうち小さい順に n 個の和)
# を求める作業を left = n,n+1,…,2n について行ってその最大値を求める
# si := 左 i 個分の大きい順に n 個の総和 # 前処理
que1 = []
for i in range(n):
# print(s)
# print(que1)
# i = 2, 3
for i in range(n, n * 2):
heapq.heappushpop(que1, ai) else:
# print(s)
# ti := 右 i 個分の小さい順に n 個の総和 que2 = []
for i in range(n):
# print(t)
# print(que2)
# i = 2, 3
for i in range(n, n * 2):
else:
# print(t)
# 集計
res = -pow(10, 10000)
# i = 2, 3, 4
for i in range(n, n * 2 + 1):
# print(i, n * 3 - i)
# 2 4
# 3 3
# 4 2
print(res)
テーマ
メモ
解答
code: python
n = int(input())
a = list(map(int, input().split()))
# print(a)
# 全探索: O(pow(2, 1000))
# 最初から分割する意味はない
# a1.sort()
# a2.sort()
# print(a1)
# print(a2)